<template>
  <div>
    <button @click="updateData">更新数据</button>
    <p>{{ message }}</p>
  </div>
</template>

<script>
import axios from 'axios';

export default {
  data() {
    return {
      message: ''
    };
  },
  methods: {
    async updateData() {
      try {
        const response = await axios.post('http://localhost:3001/api/updateData', {
          id: 1, // 假设要更新的数据的 id 为 1
          field1: 'new value 1',
          field2: 'new value 2'
        });
        this.message = response.data.message;
      } catch (error) {
        console.error('请求出错:', error);
        this.message = '更新数据失败';
      }
    }
  }
};
</script>